home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2512 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.gate.net!pslfl2-35
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: cpp question
  5. Date: 21 Jan 1996 13:28:15 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4dtf1f$21r4@news.gate.net>
  8. References: <4drm99$j0m@peabody.colorado.edu>
  9. NNTP-Posting-Host: pslfl2-35.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4drm99$j0m@peabody.colorado.edu>,
  13.    woodjr@rintintin.Colorado.EDU (WOOD  JAMEY RYAN) spake:
  14. ;I have something like this:
  15. ;
  16. ;     #define USERLEN 8
  17. ;     #define HOSTLEN 15
  18. ;
  19. ;     char name[] = "woodjr";
  20. ;     char host[] = "really.long.hostname.com";
  21. ;     char s[100];
  22. ;
  23. ;     sprintf(s, "%.USERLENs@%.HOSTLENs", name, host);
  24. ;
  25. ;And I want cpp to parse the sprintf line to:
  26. ;
  27. ;     sprintf(s, "%.8s@%.15s", name, host);
  28. ;
  29. ;Which it (of course) isn't doing.  Is there some syntax I
  30. ;can use to get it to do this?
  31.  
  32. There shur is:
  33.  
  34.      sprintf(s, "%.*s@%.*s", USERLEN, name, HOSTLEN, host);
  35.  
  36. The asterisk in the width.precision fields in the formatting sequence allows 
  37. you to include the size as an integer value in your parameter list.
  38.  
  39. Bill
  40.  
  41. "Whatcha got on?...Your mind?"
  42.